import Vue from "vue";
import Router from "vue-router";
import Home from "../Home.vue";
import Layout from "@/components/Layout/index.vue";
Vue.use(Router);

const router = new Router({
  mode: "history",
  routes: [
    // {
    //   path: '/Login',
    //   component: Login,
    //   name: '登录',
    //   hidden: true
    // },
    {
      path: "/",
      component: Layout,
      name: "主页",
      iconCls: "el-icon-message", //图标样式class
      leaf: true, //只有一个节点
      redirect: "/index",
      children: [
        { path: "/index", component: Home, name: "首页" },
        {
          path: "/moralCultivation",
          component: () => import("@/page/moralCultivation.vue"),
          name: "道德与法治"
        },
        {
          path: "/moralCultivationDetail",
          component: () => import("@/page/moralCultivationDetail.vue"),
          name: "课程详情"
        },
        {
          path: "/information",
          component: () => import("@/page/person/information.vue"),
          name: "个人资料"
        },
        {
          path: "/help",
          component: () => import("@/page/person/help.vue"),
          children: [
            {
              path: "aboutUs",
              component: () => import("@/page/person/aboutUs.vue"),
              name: "关于我们"
            },
            {
              path: "serviceCenter",
              component: () => import("@/page/person/serviceCenter.vue"),
              name: "客服中心"
            },
            {
              path: "problem",
              component: () => import("@/page/person/problem.vue"),
              name: "常见问题"
            },
            {
              path: "feedback",
              component: () => import("@/page/person/feedback.vue"),
              name: "意见反馈"
            }
          ]
        },
        {
          path: "/personal",
          component: () => import("@/page/person/personal.vue"),
          children: [
            {
              path: "collect",
              component: () => import("@/page/person/collect.vue"),
              name: "我的收藏"
            },
            {
              path: "teacher",
              component: () => import("@/page/person/teacher.vue"),
              name: "名师功能"
            },
            {
              path: "focus",
              component: () => import("@/page/person/focus.vue"),
              name: "我的关注"
            },
            ,
            {
              path: "fans",
              component: () => import("@/page/person/fans.vue"),
              name: "我的粉丝"
            },
            {
              path: "organization",
              component: () => import("@/page/person/organization.vue"),
              name: "我的组织"
            },
            {
              path: "course",
              component: () => import("@/page/person/course.vue"),
              name: "我的课程"
            }
          ]
        },
        {
          path: "applyMatster",
          component: () => import("@/page/person/applyMaster.vue"),
          name: "我的课程"
        },
        {
          path: "/news",
          component: () => import("@/page/news.vue"),
          name: "新闻资讯"
        },
        {
          path: "/newDateil",
          component: () => import("@/page/newDetails.vue"),
          name: "新闻详情"
        },
        {
          path: "/notice",
          component: () => import("@/page/notice.vue"),
          name: "公告"
        },
        {
          path: "/message",
          component: () => import("@/page/message.vue"),
          name: "消息"
        },
        {
          path: "/teacherDon",
          component: () => import("@/page/teacherDon.vue"),
          name: "名师堂"
        },
        {
          path: "/teacherDonDateil",
          component: () => import("@/page/teacherDonDateil.vue"),
          name: "名师详情"
        },
        {
          path: "/trainingService/:id",
          component: () => import("@/page/trainingService.vue"),
          name: "培训服务",
          props: true
        },
        {
          path: "/myTraining/:id/:type",
          component: () => import("@/page/myTraining.vue"),
          name: "我的培训",
          props: true
        },
        {
          path: "/trainingDetail/:id/:trainId",
          component: () => import("@/page/trainingDetail.vue"),
          name: "培训详情"
        }
      ]
    }
  ]
});
router.beforeEach((to, from, next) => {
  const title = to && to.name;
  if (title) {
    document.title = title;
  }
  next();
  // NProgress.start();
  // if (to.path == "/Login") {
  //   next();
  //   // NProgress.done();
  //   return;
  // }
  //获取权限
  // permission.init(to.path, router.options.routes).then(function(d) {
  //   if (d) {
  //     if (d.code == 404) {
  //       next({ path: "/404" });
  //     } else if (d.code == 110 && to.path != "/Login") {
  //       next({ path: "/Login" });
  //     } else if (d.code == 1 && d.data) {
  //       //动态菜单
  //       d.data.forEach(e => {
  //         if (e.path) {
  //           e.component = () => import(`@/views${e.path}`);
  //         }
  //         e.children.forEach(c => {
  //           if (c.path) {
  //             c.component = () => import(`@/views${c.path}`);
  //           }
  //         });
  //       });
  //       // 将生成数组树结构的菜单并拼接404路由
  //       const routes = d.data.concat(router.options.routes);
  //       router.options.routes = routes;
  //       router.addRoutes(d.data);
  //       // 动态新增可访问路由表
  //       next({ path: to.path }); // hack方法 确保addRoutes已完成
  //     } else {
  //       next();
  //     }
  //   } else {
  //     next();
  //   }
  //   NProgress.done();
  // });
});

router.afterEach(() => {
  // NProgress.done(); // finish progress bar
});
Vue.use(Router);
export { router };
